#include <stdio.h>
#include <stdlib.h>

void print_all(FILE *stream)
{
    int c;
    while ( (c = getc(stream)) != EOF )
    {
        putchar(c);
        // putc(int _Character, FILE *_Stream);
    }
}

/*
This program runs a process (netstat) via popen() and reads all the standard output from the process and echoes
that to standard output.

Note: popen() does not exist in the standard C library, but it is rather a part of POSIX C)
*/
int main(void)
{
    FILE *stream;
    /*
    call netstat command . netstat is available for windows and linux
    */
   if ((stream = popen("netstat", "r")) == NULL )
   {
       return 1;
   }
   print_all(stream);
   pclose(stream);
   system("notepad");
   return 0;
}